﻿@using Common.Property

@{
    Layout = "~/Views/Shared/_Edit.cshtml";
}
@model DTO.DTO.Draw.Entry.EntryDetailDTO
<form class="layui-form" action="" style="margin-top:20px;">
    <input type="hidden" name="Id" value="@Model.Id" />
    <div class="layui-form-item">
        <label class="layui-form-label">分类</label>
        <div class="layui-input-inline">
            <select id="selType" name="Type" lay-filter="typeChange">
                @foreach (Domain.Com.BasicType item in ViewBag.Types)
                {
                    if (item.Id == Model.Type)
                    {
                        <option value="@(item.Id)" selected="">@(item.Title)</option>
                    }
                    else
                    {
                        <option value="@(item.Id)">@(item.Title)</option>
                    }
                }
            </select>
        </div> 
        <div class="layui-input-inline">
            <select id="selType2" name="Type2" lay-filter="type2Change">
                <option value="">分类2</option>
                @foreach (Domain.Com.BasicType item in ViewBag.Types2)
                {
                    if (item.Id == Model.Type2)
                    {
                        <option value="@(item.Id)" selected="">@(item.Title)</option>
                    }
                    else
                    {
                        <option value="@(item.Id)">@(item.Title)</option>
                    }
                }
            </select>
        </div> 
        <div class="layui-input-inline">
            <select id="selType3" name="Type3">
                <option value="">分类3</option>
                @foreach (Domain.Com.BasicType item in ViewBag.Types3)
                {
                    if (item.Id == Model.Type3)
                    {
                        <option value="@(item.Id)" selected="">@(item.Title)</option>
                    }
                    else
                    {
                        <option value="@(item.Id)">@(item.Title)</option>
                    }
                }
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="Title" lay-verify="required" autocomplete="off" placeholder="标题" class="layui-input" value="@Model.Title">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" @(Model.Status == E_Status.Enabled.ToString() ? "checked=''" : "") name="Status" lay-skin="switch" lay-filter="switchTest" lay-text="正常|禁用">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="submit">保存</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
@section script {
    <script>

        layui.use(['form'], function () {
            var form = layui.form
                , layer = layui.layer
                , $ = layui.$;


            var index = parent.layer.getFrameIndex(window.name);
            //监听提交
            form.on('submit(submit)', function (data) {
                var formData = data.field;
                formData.Status = formData.Status === "on" ? "@E_Status.Enabled.ToString()" : "@E_Status.Disable.ToString()";
                $.post("Save", formData, function (d) {
                    if (d.code === 0) {
                        layer.msg(d.msg, { icon: 1 });
                        setTimeout(function () {
                            parent.layer.close(index);
                        }, 1000);
                    }
                    else {
                        layer.msg(d.msg, { icon: 2 });
                    }
                })
                return false;
            });


            form.on('select(typeChange)', function (data) {
                $("#selType2").empty();
                $("#selType2").append("<option value=\"\">分类2</option>");
                $("#selType3").empty();
                $("#selType3").append("<option value=\"\">分类3</option>");
                var type = $("#selType").val();
                if (type) {
                    $.post("/Basic/BasicType/GetList", { Type: "EntryType", ParentId: type }, function (d) {
                        if (d.code === 0) {
                            d.data.forEach(function (item) {
                                $("#selType2").append("<option value=\"" + item.id + "\">" + item.title + "</option>");
                            });
                        }
                        form.render('select');
                    });
                }else{
                    form.render('select');
                }
            });

            form.on('select(type2Change)', function (data) {
                $("#selType3").empty();
                $("#selType3").append("<option value=\"\">分类3</option>");
                var type2 = $("#selType2").val();
                if (type2) {
                    $.post("/Basic/BasicType/GetList", { Type: "EntryType", ParentId: type2 }, function (d) {
                        if (d.code === 0) {
                            d.data.forEach(function (item) {
                                $("#selType3").append("<option value=\"" + item.id + "\">" + item.title + "</option>");
                            });
                        }
                        form.render('select');
                    });
                }else{
                    form.render('select');
                }
            });
        });
    </script>
}

